// 封装轻提示 -- 基于elmui
import { Message, MessageBox } from 'element-ui'

export function success(str, time) {
  Message.success({
    message: str,
    duration: time || 1500
  })
}
export function error(str, time) {
  Message.error({
    message: str,
    duration: time || 1500
  })
}
export function info(str, time) {
  Message.info({
    message: str,
    duration: time || 1500
  })
}
export function warning(str, time) {
  return new Promise((resolve, reject) => {
    Message.warning({
      message: str,
      duration: time || 1500
    })
    setTimeout(() => resolve(), time || 1500)
  })
}

/* 是否确认删除 */
export function okBox(str) {
  return new Promise((resolve, reject) => {
    MessageBox.confirm(`此操作将永久${str}, 是否继续?`, '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '取消',
      type: 'warning'
    })
      .then(() => {
        /* 点击确定 */
        resolve()
      })
      .catch(() => {
        info('已取消')
      })
  })
}

/* 其他待测试的功能 */
export function createUniqueString() {
  const timestamp = +new Date() + ''
  const randomNum = parseInt((1 + Math.random()) * 65536) + ''
  return (+(randomNum + timestamp)).toString(32) //  32进制
}
